package org.usmile.algorithms.huawei.acm;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

// https://blog.csdn.net/amos_cloud/article/details/128348549
public class _任务混部 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[][] ranges = new int[n][3];

        for (int i = 0; i < n; i++) {
            ranges[i][0] = sc.nextInt();
            ranges[i][1] = sc.nextInt();
            ranges[i][2] = sc.nextInt();
        }

        System.out.println(getResult(ranges));
    }

    public static int getResult(int[][] ranges) {
        Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));

        PriorityQueue<Integer[]> heap = new PriorityQueue<>(Comparator.comparingInt(a -> a[0]));

        int max = 0;
        int sum = 0;
        for (int[] range : ranges) {
            int start = range[0];
            int end = range[1];
            int parallelism = range[2];

            while (heap.size() > 0) {
                Integer[] curr = heap.peek();
                if (curr[0] <= start) {
                    curr = heap.poll();
                    sum -= curr[1];
                } else {
                    break;
                }
            }

            heap.offer(new Integer[]{end, parallelism});
            sum += parallelism;

            if (sum > max) {
                max = sum;
            }
        }
        return max;
    }

}
